package generadorDescriptores.dom;

import java.util.ArrayList;

import generadorDescriptores.AttributesData;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class JoinDom {
	private Element elementJoin; 
	private Document document;
	private ArrayList<ConditionJoin> conditions;
	
	public JoinDom(Document doc){
		this.document = doc;
		elementJoin = doc.createElement("join");
		conditions = new ArrayList<ConditionJoin>();
	}
	
	
	/**
	 * This method will be invoked from the UI.
	 * @param name
	 * @param table
	 * @param column
	 * @param factColumn
	 */
	public void setAttributes(String name, String table){
		Element elem = this.elementJoin;
		elem.setAttribute("name", name);
		elem.setAttribute("table", table);
	}

	public Element getElement() {
		return this.elementJoin;
	}
	
	public void addCondition(AttributesData data){
		ConditionJoin condition = new ConditionJoin(document);
		condition.setAttributes(data.getConditionJoinColumn(), data.getConditionJoinFactColumn());
		conditions.add(condition);
		this.elementJoin.appendChild(condition.getElement());
	}
	
	
}
